package com.test.controller.messageResource;

import com.test.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

/**
 * 创建人： HBZ，时间： 2017/9/2 10:57.
 * 说明：messageResource控制器
 */
@Controller
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageSource messageSource;

    private String domain="message";
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ModelAndView index(HttpServletRequest request, ModelMap model, Locale locale) {

        System.out.println(messageSource.getMessage("msg.name",null,new Locale("zh","CN")));
        System.out.println(messageSource.getMessage("msg.name",null,new Locale("en","US")));
        System.out.println(messageSource.getMessage("msg.name",null,Locale.getDefault()));
        System.out.println(messageSource.getMessage("msg.name",null,locale));
        return new ModelAndView(domain+"/hello");

    }
}
